/*
 * Copyright 2008 Karel Klic.
 * This file is part of Oslavanský Bot.
 * 
 * Oslavanský Bot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package categorybot;

import org.apache.commons.cli.*;

public class Settings {
  
  private Options options;
  
  public Settings() {
    options = new Options();
    Option userName = OptionBuilder
            .withArgName("name")
            .hasArg()
            .isRequired()
            .withDescription("czech wiktionary user name")
            .withLongOpt("username")
            .create('u');
    Option password = OptionBuilder
            .withArgName("password")
            .hasArg()
            .isRequired()
            .withDescription("user password")
            .withLongOpt("password")
            .create('p');
    Option help = OptionBuilder
            .withDescription("print this message")
            .withLongOpt("help")
            .create('h');
    Option wordLimit = OptionBuilder
            .withDescription("max. number of words checked")
            .withArgName("number")
            .hasArg()
            .withLongOpt("limit")
            .create('l');
    Option from = OptionBuilder
            .withDescription("page title to start from")
            .withArgName("word")
            .hasArg()
            .withLongOpt("from")
            .create('f');
    Option prefix = OptionBuilder
            .withDescription("restrict search to titles that begin with this value")
            .withArgName("prefix")
            .hasArg()
            .withLongOpt("prefix")
            .create();
    Option commit = OptionBuilder
            .withDescription("Sends the changes to the real wikipedia")
            .withLongOpt("commit")
            .create();
    options.addOption(help);
    options.addOption(password);
    options.addOption(userName);
    options.addOption(wordLimit);
    options.addOption(from);
    options.addOption(prefix);
    options.addOption(commit);
  }
  
  public CommandLine parse(String[] args) throws ParseException {
    CommandLineParser parser = new GnuParser();
    // parse the command line arguments
    return parser.parse(options, args);
  }
  
  public void showHelp() {
    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("categorybot", options);    
  }
}
